package com.hhd.flow.controller;

import com.hhd.flow.vo.Result;
import com.hhd.flow.vo.SubtractAbleUserSignVo;
import com.hhd.flow.engine.FlowEngine;
import com.hhd.flow.engine.cmd.impl.QuerySubtractAbleUserSignCommand;
import com.hhd.flow.engine.cmd.impl.SubtractUserSignCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/flow")
public class SubtractAbleUserController {
    @Autowired
    FlowEngine flowEngine;

    @GetMapping("/querySubtractAbleUserSign")
    public Result querySubtractAbleUserSign(String flowUserTaskId) {
        QuerySubtractAbleUserSignCommand command = flowEngine.newQuerySubtractAbleUserSignCommandBuilder()
                .flowUserTaskId(flowUserTaskId)
                .build();
        return Result.ok(flowEngine.execute(command).getResult());
    }

    @PostMapping("/subtractAbleUserSign")
    @Transactional
    public Result subtractAbleUserSign(@RequestBody SubtractAbleUserSignVo subtractAbleUserSignVo) {
        SubtractUserSignCommand command = flowEngine.newSubtractUserSignCommandBuilder()
                .flowUserTaskId(subtractAbleUserSignVo.getFlowUserTaskId())
                .userTaskId(subtractAbleUserSignVo.getUserTaskId())
                .build();
        return Result.ok(flowEngine.execute(command).getResult());
    }
}
